package com.ruoyi.web.controller.TiebaComments.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.web.controller.TiebaComments.domain.TiebaComments;
import com.ruoyi.web.controller.TiebaComments.mapper.TiebaCommentsMapper;
import com.ruoyi.web.controller.TiebaComments.service.ITiebaCommentsService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.ruoyi.common.utils.StringUtils;
import java.util.List;
import java.util.Map;

/**
 * 用户评论帖子Service业务层处理
 *
 * @author yong
 * @date 2025-03-09
 */
@Service
public class TiebaCommentsServiceImpl extends ServiceImpl<TiebaCommentsMapper, TiebaComments> implements ITiebaCommentsService {

    @Autowired
    private TiebaCommentsMapper tiebaCommentsMapper;

    /**
     * 查询用户评论帖子列表
     *
     * @param tiebaComments 用户评论帖子
     * @return 用户评论帖子
     */
    @Override
    public List<TiebaComments> selectTiebaCommentsList(TiebaComments tiebaComments)
    {
        List<TiebaComments> tiebaCommentsList = tiebaCommentsMapper.selectList(buildQueryWrapper(tiebaComments));
        return tiebaCommentsList;
    }


    private LambdaQueryWrapper<TiebaComments> buildQueryWrapper(TiebaComments query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<TiebaComments> lqw = Wrappers.lambdaQuery();
        lqw.eq(query.getPostId() != null, TiebaComments::getPostId, query.getPostId());
//        lqw.eq(query.getUserId() != null, TiebaComments::getUserId, query.getUserId());
//        lqw.eq(query.getDeptId() != null, TiebaComments::getDeptId, query.getDeptId());
//        lqw.eq(StringUtils.isNotBlank(query.getContent()), TiebaComments::getContent, query.getContent());
        lqw.orderByDesc(TiebaComments::getCreateTime);
        return lqw;
    }

}
